package com.qf.test.test.controller;

import com.qf.test.test.pojo.User;
import com.qf.test.test.servler.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;
    //使用log4j的logger对象



    //springMvc会注入这个对象  因为request  respponse  session model是spring默认支持的参数
    @Autowired
    private HttpServletRequest request;
    /**
     * 查询所有 用户返回的数据
     */
    @RequestMapping("/list")
    public String userList(Model model){
        //1调用service查询
        List<User> list = userService.findUserAll();
        //2.将返回的数据放入model中带会给页面展示
        model.addAttribute("users",list);
        //3.指定页面的位置
        return "user";
    }

    @RequestMapping("/list1")
    public String userListAndByname(Model model){
        //1调用service查询
        List<User> list = userService.findByNameAndSexAndBirthday();
        //2.将返回的数据放入model中带会给页面展示
        model.addAttribute("users",list);
        //3.指定页面的位置
        return "user";
    }
}
